package net.sxnic.workflow.action;

import net.sxnic.ugr.context.AppContext;
import net.sxnic.ugr.user.User;
import net.sxnic.workflow.WfActionSupport;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

@SuppressWarnings("serial")
public class SignPwdVerify extends WfActionSupport {

	/**
	 * 要验证的签字密码
	 */
	private String signPwd;

	/**
	 * 验证结果 t验证成功 f验证失败
	 */
	private String verifyResult;

	public String execute() {
		if (StringUtils.isBlank(signPwd)) {
			verifyResult = "f";
		}

		User user = userManager.getUserByUsername(AppContext
				.getUserName(request));

		if (!DigestUtils.md5Hex(signPwd).equals(user.getSignPwd())) {
			verifyResult = "f";
		} else {
			verifyResult = "t";
		}

		return SUCCESS;
	}

	public String getSignPwd() {
		return signPwd;
	}

	public void setSignPwd(String signPwd) {
		this.signPwd = signPwd;
	}

	public String getVerifyResult() {
		return verifyResult;
	}

	public void setVerifyResult(String verifyResult) {
		this.verifyResult = verifyResult;
	}
}
